﻿using PushBox.Core;
using System;

namespace PushBox.Con
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string str = @"
 #######
##     #
##  +  #
#   ** +#
#  @    #
#       #
#########
";
            Map m = new Map(str);
            m.DoDraw = DrawMap;
            m.DoDraw(m);
            Console.CursorVisible = false;
            while (!m.IsPassed())
            {
                Console.SetCursorPosition(0, 0);
                ConsoleKeyInfo k = Console.ReadKey();
                switch (k.Key)
                {
                    case ConsoleKey.LeftArrow:
                        m.Person.Move(MoveType.Left);
                        break;
                    case ConsoleKey.UpArrow:
                        m.Person.Move(MoveType.Up);
                        break;
                    case ConsoleKey.RightArrow:
                        m.Person.Move(MoveType.Right);
                        break;
                    case ConsoleKey.DownArrow:
                        m.Person.Move(MoveType.Down);
                        break;
                }
            }
            Console.WriteLine("过关");
        }

        static void DrawMap(Map map)
        {
            for (int y = 0; y < map.Height; y++)
            {
                for (int x = 0; x < map.Width; x++)
                {
                    Position p = map.GetObject(x, y);
                    if (p is Box) Console.Write("*");
                    else if (p is Wall) Console.Write("#");
                    else if (p is Person) Console.Write("@");
                    else if (p is Key) Console.Write("+");
                    else Console.Write(" ");
                }
                Console.WriteLine();
            }
        }
    }
}
